package com.longyi.tenant;

import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description 租户过滤器
 * @Date 2020-08-26 5:36 下午
 * @Author wuyanshen
 */
@Component
public class TenantFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        String tenantId = request.getHeader("tenantId");
        if(tenantId != null){
            TenantHolder.setTenantId(Integer.parseInt(tenantId));
        }
        filterChain.doFilter(request, response);
        TenantHolder.clear();
    }
}
